package com.holly.unit.deform.modular.controller;

import com.holly.unit.core.pojo.request.BaseRequest;
import com.holly.unit.core.pojo.response.ResponseData;
import com.holly.unit.core.pojo.response.SuccessResponseData;
import com.holly.unit.db.api.pojo.page.PageResult;
import com.holly.unit.deform.api.DeformRouterApi;
import com.holly.unit.deform.api.pojo.route.DesignFormRouteDTO;
import com.holly.unit.deform.api.pojo.route.DesignFormRouteRequest;
import com.holly.unit.deform.entity.DesignFormRoute;
import com.holly.unit.deform.modular.pojo.DesignFormDelRequest;
import com.holly.unit.deform.modular.pojo.DesignFormQueryByIdRequest;
import com.holly.unit.scanner.api.annotation.ApiResource;
import com.holly.unit.scanner.api.annotation.GetResource;
import com.holly.unit.scanner.api.annotation.PostResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 类描述: 表单设计 路由控制器
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/4/12 8:11
 */
@RestController
@ApiResource(name = "表单设计器 路由")
@Api(tags = "表单设计器 路由")
public class DeformRouteController {

    @Resource
    private DeformRouterApi api;

    /**
     * 新增
     *
     * @param designFormRouteRequest
     * @return
     */
    @ApiOperation(value = "_增加" ,notes = "_增加")
    @PostResource(name = "_增加", path = "/designFormRoute/add", requiredPermission = false , requiredLogin = false)
    public ResponseData add(@RequestBody @Validated(BaseRequest.add.class) DesignFormRouteRequest designFormRouteRequest) {
        api.add(designFormRouteRequest);
        return new SuccessResponseData();
    }

    /**
     * 删除
     *
     * @author holly
     * @date 2022-03-03 03:35:57
     */
    @ApiOperation(value = "_删除" ,notes = "_删除")
    @PostResource(name = "_删除", path = "/designFormRoute/delete", requiredPermission = false , requiredLogin = false)
    public ResponseData delete(@RequestBody @Validated(DesignFormRouteRequest.delete.class) DesignFormRouteRequest designFormRouteRequest) {
        api.del(designFormRouteRequest);
        return new SuccessResponseData();
    }
    /**
     * 详情
     *
     * @author holly
     * @date 2022-03-03 03:35:57
     */
    @ApiOperation(value = "_详情" ,notes = "_详情")
    @PostResource(name = "_详情", path = "/designFormRoute/detail", requiredPermission = false , requiredLogin = false)
    public ResponseData detail(@RequestBody @Validated(DesignFormRouteRequest.detail.class) DesignFormRouteRequest designFormRouteRequest) {
        DesignFormRouteDTO designFormRouteDTO = api.detail(designFormRouteRequest);
        return new SuccessResponseData(designFormRouteDTO);
    }

    /**
     * 导出
     *
     * @author holly
     * @date 2022-03-03 03:35:57
     */
    @ApiOperation(value = "_导出" ,notes = "_导出")
    @GetResource(name = "_导出", path = "/designFormRoute/export", requiredPermission = false , requiredLogin = false)
    public void export(HttpServletResponse response) {
        api.export(response);
    }

    /**
     * 分页列表查询
     *
     * @author holly
     * @date 2022-03-03 03:35:57
     */
    @ApiOperation(value = "分页查询" ,notes = "分页查询")
    @GetResource(name = "分页查询", path = "/designFormRoute/page", requiredPermission = false , requiredLogin = false)
    public ResponseData page(DesignFormRouteRequest designFormRouteRequest) {
        return new SuccessResponseData(api.findPage(designFormRouteRequest));
    }

    /**
     * 列表查询
     *
     * @author holly
     * @date 2022-03-03 03:35:57
     */
    @ApiOperation(value = "列表查询" ,notes = "列表查询")
    @GetResource(name = "列表查询", path = "/designFormRoute/list", requiredPermission = false , requiredLogin = false)
    public ResponseData list(DesignFormRouteRequest designFormRouteRequest) {
        return new SuccessResponseData(api.findList(designFormRouteRequest));
    }


    /**
     * 分页列表查询
     *
     * @param designFormRoute
     * @param request
     * @return
     */
    @ApiOperation(value = "表单设计器路由跳转配置表-分页列表查询", notes = "表单设计器路由跳转配置表-分页列表查询")
    @GetResource(name = "表单设计器路由跳转配置表-分页列表查询" , path = "/designFormRoute/queryPageList")
    public ResponseData queryPageList(DesignFormRoute designFormRoute, HttpServletRequest request) {
        PageResult<DesignFormRoute> pageResult = api.fetchPageList(designFormRoute, request.getParameterMap());
        return new SuccessResponseData(pageResult);
    }


    /**
     * 编辑
     *
     * @param designFormRoute
     * @return
     */
    @ApiOperation(value = "表单设计器路由跳转配置表-编辑", notes = "表单设计器路由跳转配置表-编辑")
    @PostResource(name = "表单设计器路由跳转配置表-编辑" , path = "/designFormRoute/edit")
    public ResponseData edit(@RequestBody DesignFormRoute designFormRoute) {
        api.editEntity(designFormRoute);
        return  new SuccessResponseData();
    }

    /**
     * 批量删除
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "表单设计器路由跳转配置表-批量删除", notes = "表单设计器路由跳转配置表-批量删除")
    @PostResource(name = "表单设计器路由跳转配置表-批量删除" , path = "/designFormRoute/deleteBatch")
    public ResponseData deleteBatch(@Validated(DesignFormDelRequest.delByIds.class) DesignFormDelRequest request) {
        api.delBatch(request.getIds());
        return new SuccessResponseData();
    }

    /**
     * 通过id查询
     *
     * @param request 主键id
     * @return
     */
    @ApiOperation(value = "表单设计器路由跳转配置表-通过id查询", notes = "表单设计器路由跳转配置表-通过id查询")
    @GetResource(name = "表单设计器路由跳转配置表-通过id查询" , path = "/designFormRoute/queryById")
    public ResponseData queryById(@Validated(DesignFormQueryByIdRequest.queryById.class) DesignFormQueryByIdRequest request) {
        DesignFormRoute designFormRoute = (DesignFormRoute)api.fetchEntityById(request.getId());
        return new SuccessResponseData(designFormRoute);
    }

}
